/*创建服务器*/
let http = require('http');
let url = require('url');
let util = require('util');
let fs = require('fs');

let server = http.createServer((req, res) => {
    let pathname = (url.parse(req.url).pathname).substring(1);
    console.log(pathname);

    fs.readFile(pathname, function (err, data) {
        if (err) {
            res.writeHead(404, {'Content-Type': 'text/html'});
        } else {
            res.writeHead(200, {'Content-Type': 'text/html'});
            res.write(data.toString());
        }

        res.end();
    });

}).listen(3000, '127.0.0.1', () => {
    console.log('服务启动成功');
});